<?php

// 表单验证

use App\Exceptions\MyException;

if (!function_exists('my_validator')) {
    /**
     * 更新自定义配置
     * @return string
     */
    function my_validator(array $item, $throwException = true)
    {
        $validator = validator()->make(request()->all(), $item);
        if ($validator->fails()) {
            if ($throwException) {
                throw new MyException($validator->errors()->first());
            } else {
                return $validator->errors()->first();
            }
        }
        return null;
    }
}
